import request from '@/utils/request';
import { AxiosPromise } from 'axios';
import { HotListVO, PostsVO, TableData } from './types';
// import {   } from '@/api/front/social/types';

/**
 * @description 帖子列表
 * @param query {
 *    categoryId: 0 帖子 1 交流
 *    userId: 用户id
 *    cursorId: 游标id
 *    recommendScore: 推荐分数
 * }
 * @returns 
 */
export const socialList = (query?: any,headers?:any): AxiosPromise<any> => {
    return request({
      url: '/api/posts/page/list',
      method: 'post',
      data: query,
      headers:headers
    });
};

/**
 * @description 热门帖子排行榜
 * @param query 
 * @returns 
 */
export const hotList= (query?: any): AxiosPromise<HotListVO[]> => {
    return request({
      url: '/api/posts/list/hot',
      method: 'get',
      params: query
    });
};

/**
 * @description 帖子详情
 * @param number 文章id 
 * @returns 
 */
export const postsDetails= (number?: any): AxiosPromise<any> => {
    return request({
      url: '/api/posts/'+number,
      method: 'get'
    });
};

/**
 * @description 更新帖子阅读次数
 * @param query {
  "postsId": "1863608016219246524"
}
 * 
 * 
 * @returns 
 */
export const updateView = (query?: any): AxiosPromise<any> => {
    return request({
      url: '/api/posts/posts_view',
      method: 'post',
      data: query
    });
};

/**
 * @description 查询用户保存的帖子
 * @param 不用传，带token就行
 * @returns 
 */
export const getDraft= (query?: any): AxiosPromise<any> => {
    return request({
      url: '/api/posts/get/draft',
      method: 'get',
      data: query
    });
};

/**
 * @description 查询用户拥有的帖子
 * @param query  ?pageNum=1&pageSize=10
 * @returns 
 */
export const getUserPostsList= (query?: any): AxiosPromise<TableData<PostsVO>> => {
    return request({
      url: '/api/posts/list/user',
      method: 'get',
      params: query
    });
};

/**
 * @description 更新帖子阅读次数
 * @param query # 保存帖子
{
    "title": "测试保存文章",
    "content": "测试",
    "releaseFlag": "N",
    "remark": "222",
    "tags": ["寻找渔友", "demo"]
}
    # 发布帖子
{
    "postsId": "1864593525984833538",
    "title": "测试保存文章",
    "content": "测试",
    "releaseFlag": "Y",
    "remark": "222",
    "tags": ["寻找渔友", "demo"]
}
 * 
 * 
 * @returns 
 */
export const publishPosts = (query?: any): AxiosPromise<any> => {
    return request({
      url: '/api/posts/push',
      method: 'post',
      data: query
    });
}

/**
  删除帖子
 * @param query {
    "ids": []
}
 * @returns 
 */
export const deletePosts = (query?: any): AxiosPromise<any> => {
    return request({
      url: '/api/posts/delete',
      method: 'post',
      data: query
    });
}

/**
 * @description 获取用户自己收藏的帖子列表
 * @param query {
    "pageNum": "1",
    "pageSize": "10"
}
 * @returns 
 */
export const userCollectPosts = (query?: any): AxiosPromise<TableData<PostsVO>> => {
    return request({
      url: '/api/posts/user/collect',
      method: 'get',
      params: query
    });
}

/**
 * @description 用户收藏帖子
 * @param form {
 *   "postsId": "文档id",
 *   "authorId": "作者id",
 *   "type": "collect or uncollect"
 * }
 * @returns 
 */
export const collectPosts = (form?: any): AxiosPromise<any> => {
    return request({
      url: '/api/collect/posts',
      method: 'post',
      data: form
    });
}